package com.hjn.springboot.springbootservlet.servlet;

import com.hjn.springboot.springbootservlet.entity.User;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author: huaijn
 * @create: 2022/4/30 8:46
 * @description: todo
 **/
@WebServlet(name = "myservlet01", urlPatterns = "/myservlet01")
public class MyServlet01 extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req, resp);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpSession session = req.getSession();
    String id = session.getId();
    User user = (User) session.getAttribute("user");
    if (user == null) {
      session.setAttribute("user", new User("ds342jhh2342234h2jh34", "zhangsan", 13));
    }
    resp.getWriter().println("myserlvet01........" + id);
    resp.getWriter().flush();
    resp.getWriter().close();
  }


}
